import 'package:flutter/cupertino.dart';

import '../common/const/app_color_const.dart';
import '../common/const/app_style_const.dart';
import '../common/util/common_util.dart';
import '../widget/card_container.dart';
import '../widget/form_item.dart';
import '../widget/gradient_btn.dart';

class WorkOrderListItem extends StatelessWidget {
  final Map<String, dynamic> data;
  final Function(Map<String, dynamic> data) toView;

  const WorkOrderListItem({Key? key, required this.data, required this.toView})
      : super(key: key);

  Widget buildTitle(context) {
    return LayoutBuilder(builder: (buildCtx, constraints) {
      return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
        SizedBox(
          width: constraints.maxWidth / 2 + 40,
          child: Text(
            '${CommonUtil.valueEmptyToDefStr(data["createAt"])}创建',
            style: cardContainerNormalTitleStyle,
            overflow: TextOverflow.ellipsis,
          ),
        ),
        GradientBtn(
            label: "详情",
            onTap: () {
              toView(data);
            })
      ]);
    });
  }

  @override
  Widget build(BuildContext context) {
    return CardContainer(
      margin: const EdgeInsets.only(bottom: 10.0),
      titleBuilder: (context) => buildTitle(context),
      bodyPadding: const EdgeInsets.all(12.0),
      bodyBuilder: (c) => Container(
        color: lightGrayColor8,
        padding: const EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.only(bottom: 6.0),
                label: '工单号',
                valueWidth: constraints.maxWidth - 60,
                value: CommonUtil.valueEmptyToDefStr(data["workOrderNo"]),
              );
            }),
            LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.only(bottom: 6.0),
                label: '发起人',
                valueWidth: constraints.maxWidth - 60,
                value: CommonUtil.valueEmptyToDefStr(data["bookUserName"]),
              );
            }),
            LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.only(bottom: 6.0),
                label: '直播间',
                valueWidth: constraints.maxWidth - 60,
                value: CommonUtil.valueEmptyToDefStr(data["liveRoomNo"]),
              );
            }),
            LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.only(bottom: 6.0),
                label: '直播时段',
                valueWidth: constraints.maxWidth - 70,
                value:
                    '${CommonUtil.valueEmptyToDefStr(data["bookDt"])}  ${CommonUtil.valueEmptyToDefStr(data["bookStartTime"])} - ${CommonUtil.valueEmptyToDefStr(data["bookEndTime"])}',
              );
            }),
            LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.only(bottom: 6.0),
                label: '样衣数量',
                valueWidth: constraints.maxWidth - 70,
                value: CommonUtil.valueEmptyToDefStr(data["sampleGoodsNum"]),
              );
            }),
          ],
        ),
      ),
      footerPadding: (null != data["assignStaffUserName"] &&
              "" != data["assignStaffUserName"])
          ? const EdgeInsets.only(left: 12, right: 12, bottom: 12)
          : const EdgeInsets.only(left: 12, right: 12, bottom: 0),
      footerBuilder: (c) => (null != data["assignStaffUserName"] &&
              "" != data["assignStaffUserName"])
          ? LayoutBuilder(builder: (buildContext, constraints) {
              return FormItem(
                padding: const EdgeInsets.all(0),
                label: '处理人',
                valueWidth: constraints.maxWidth - 60,
                value:
                    CommonUtil.valueEmptyToDefStr(data["assignStaffUserName"]),
              );
            })
          : Container(),
    );
  }
}
